package com.groupbuying.sysconfig.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.groupbuying.sysconfig.utils.PageUtils;
import com.groupbuying.sysconfig.utils.Query;
import com.groupbuying.sysconfig.utils.R;
import com.groupbuying.sysconfig.domain.O2okindDO;
import com.groupbuying.sysconfig.dto.O2OKindDTO;
import com.groupbuying.sysconfig.service.O2okindService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * o2o门店分类
 * 
 * @author zmlmagic
 * @email 16651@mengtaigroup.com
 * @date 2019-03-11 18:43:14
 */
@Controller
@RequestMapping("/o2okind")
public class O2okindController {
	@Autowired
	private O2okindService o2okindService;

	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);
		List<O2okindDO> o2okindList = o2okindService.list(query);
		List<O2OKindDTO> resultList = new ArrayList<>();
		for(O2okindDO o2okindDO : o2okindList){
			O2OKindDTO o2OKindDTO = new O2OKindDTO();
			o2OKindDTO.setLabel(o2okindDO.getKindName());
			o2OKindDTO.setValue(o2okindDO.getKindName());
			o2OKindDTO.setImg("https://ggyd-customer-public.oss-cn-huhehaote.aliyuncs.com" + o2okindDO.getKindIcon());
			resultList.add(o2OKindDTO);
		}
		int total = o2okindService.count(query);
		PageUtils pageUtils = new PageUtils(resultList, total);
		return pageUtils;
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save(O2okindDO o2okind){
		if(o2okindService.save(o2okind)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( O2okindDO o2okind){
		o2okindService.update(o2okind);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( Long kindId){
		if(o2okindService.remove(kindId)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Long[] kindIds){
		o2okindService.batchRemove(kindIds);
		return R.ok();
	}
	
}
